{% extends 'base/base.html' %}

{% block title %}用户管理{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/admin.css' %}">
{% endblock %}

{% block sidebar %}
{# 同dashboard.html的sidebar #}
{% include 'admin/sidebar.html' %}
{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">用户管理</h1>
</div>

<div class="table-responsive">
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <th>用户名</th>
                <th>邮箱</th>
                <th>用户类型</th>
                <th>注册时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for user in page_obj %}
            <tr>
                <td>{{ user.username }}</td>
                <td>{{ user.email }}</td>
                <td>{{ user.get_user_type_display }}</td>
                <td>{{ user.date_joined|date:"Y-m-d" }}</td>
                <td>
                    {% if user.is_active %}
                    <span class="badge bg-success">活跃</span>
                    {% else %}
                    <span class="badge bg-danger">禁用</span>
                    {% endif %}
                </td>
                <td>
                    <a href="{% url 'accounts:edit_user' user.id %}" class="btn btn-sm btn-primary">编辑</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

{% if page_obj.has_other_pages %}
<nav aria-label="Page navigation">
    <ul class="pagination justify-content-center">
        {% if page_obj.has_previous %}
        <li class="page-item">
            <a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a>
        </li>
        {% endif %}
        
        {% for num in page_obj.paginator.page_range %}
        <li class="page-item {% if num == page_obj.number %}active{% endif %}">
            <a class="page-link" href="?page={{ num }}">{{ num }}</a>
        </li>
        {% endfor %}
        
        {% if page_obj.has_next %}
        <li class="page-item">
            <a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a>
        </li>
        {% endif %}
    </ul>
</nav>
{% endif %}
{% endblock %}